const http = require('http')
const url = require('url')
const fs = require('fs')
let server = http.createServer()
server.on('request',(req,res) => {
    console.log(req.url);
    if (req.url == './index.html'){
        fs.readFile("./index.html", "utf8", (err, data) => {
            if(err) throw err 
            res.writeHead(200, "success", {
                // 响应内容类型html ,编码utf-8
                "Content-Type": "text/html;charset=utf-8"
              })
              res.write(data)
              res.end()
            })
    }

   if (req.url == './index.css'){
        fs.readFile("./index.css", "utf8", (err, data) => {
            if(err) throw err 
            res.writeHead(200, "success", {
                // 响应内容类型html ,编码utf-8
                "Content-Type": "text/html;charset=utf-8"
              })
              res.write(data)
              res.end()
            })
    }
    if (req.url == './1.jpg'){
        fs.readFile("./1.jpg", (err, data) => {
            if(err) throw err 
            res.writeHead(200, "success", {
                // 响应内容类型html ,编码utf-8
                "Content-Type": 'image/jpeg'
              })
              res.write(data)
              res.end()
            })
    }
})